<{include file="shop_header.htm"}>
<script src="script/my_lightbox.js" language="javascript"></script>
<script>
closeimg='<{$config.weburl}>/image/default/icon_close.gif';
weburl='<{$config.weburl}>';
</script>
<script>
function roundAmount(n)
{  
  var   s   =   ""   +   Math.round(n*100)/100  
  var   i   =   s.indexOf('.')  
  if(i<0)   return   s   +   ".00"  
  var   t=s.substring(0,   i   +   1)   +    
		  s.substring(i   +   1,   i   +   3)  
  if(i   +   2   ==   s.length)   t   +=   "0"  
  return   t  
}
function get_sumprice(){ //计算所有商铺商品的总运费
	var emprice=0;
	var scval=0;
    <{foreach item=list from=$cart}>
	    <{if $list.company.pu>0 or $list.company.kd>0 or $list.company.ems>0}>
			scval=$('cem_<{$list.company.sell_userid}>').value;//当前商铺总邮费
			if(scval)
			{
				scval=scval.substr(scval.indexOf(',')+1,scval.length)*1;
				emprice+=scval;
			}  
		<{/if}>
	<{/foreach}>
	return emprice;
}
function select_em(id)
{	
    var emsumprice=get_sumprice();	
   	var  hval=$('h_csumprice_'+id).value*1;//当前商铺总价
	var  emval=$('cem_'+id).value;//当前商铺总邮费
	emval=emval.substr(emval.indexOf(',')+1,emval.length)*1;	
	var  sval=$('h_sumprice').value*1;
	$('show_cem_'+id).innerHTML=roundAmount(emval);
	$('s_csumprice_'+id).innerHTML=roundAmount(hval+emval);//改变后的商铺总商品价格
	$('h_emsumprice').value=emsumprice;//所有商铺总邮费
	var sumprice=$('h_sumprice').value;//总价不含邮费
	$('s_sumprice').innerHTML=roundAmount(emsumprice*1+sumprice*1); 
}
function check()
{
   var obj=document.getElementsByName('adder');
   var length=obj.length;
   
   //地址判断
   //无地址
   if(obj.type=='hidden')
   {  
	   alert('请填写收货地址');
	    $('adderid').style.background='#FFBABA';
	   $('adderid').focus();
	   return false;
   }
   //如果有地址
   if(obj[0].type=='radio')
   {  
	  var  flag=false;
	  for(var j=0;j<obj.length;j++){		
		   if(obj[j].checked){
				flag=true;
		   }
	  }
		if(!flag){
		   alert('请选择收货地址');
		    $('adderid').style.background='#FFBABA';
		   $('adderid').focus();
		   return false;
		}
   }	
   //如果买家承担运费是否有邮费
    <{foreach item=list from=$cart}>
	    <{if $list.company.pu>0 or $list.company.kd>0 or $list.company.ems>0}>		
   if($('cem_<{$list.company.sell_userid}>').value=='')//当前商铺总邮费
	{     
	     alert('请选择运送方式');
		 $('cem_<{$list.company.sell_userid}>').focus();
		 return false;
	}		
		<{/if}>
	//判断留言是否超过100;
	 length=$('msg_<{$list.company.sell_userid}>').value.length;
	 if(length>100){
		 alert('留言不能超过100');
		 $('msg_<{$list.company.sell_userid}>').focus();
		 return false;
	 }
	<{/foreach}>
      

}
function showadder(){
   //清空 
    <{foreach item=list key=num from=$listadder}>
	     $('ar_show_<{$list.id}>').className="";
	<{/foreach}>	
	 var obj=document.getElementsByName('adder');
	  for(var j=0;j<obj.length;j++){		
		   if(obj[j].checked){
			 $('ar_show_'+obj[j].value).className="adder";
			 $('show_adder_c').innerHTML=$('ar_content_'+obj[j].value).innerHTML;
		   }
	  }	

   //改变字体
}
function ftextarea(id,classname){
	$(id).className=classname;
}
</script>
<style>
.adder{ font-size:18px; color:#FF0000; border:1px #FFCE9D  solid;}
.textarea{ height:18px; width:160px;}
.textarea1{ height:36px; width:320px;}
</style>
<div class="menu_bottom L1">				
    <div class="headtop_L">
        <{$lang.you_are_here}><a href='<{$config.weburl}>/'><{$lang.indexpage}></a> &raquo; 订单确认
    </div>	
</div>

<div id="mainbody1" class="m1">	
   <strong>确认收货地址 [<a target="_blank" href="<{$config.weburl}>/main.php?action=m&m=product&s=admin_orderadder&menu=user">管理收货地址</a>]</strong><br />
   <form  method="post"  action="" name="form1" onsubmit="return check();">
  <table width="100%" border="0" cellspacing="1" bgcolor="#BAD9EF" class="order_table">
    <tr>
      <td bgcolor="#FFFFFF" scope="col" id="adderid">
         <{if empty($listadder)}>
         <a href="javascript:alertWin('添加新的收货地址','添加新的收货地址',600,400,'<{$config.weburl}>/?m=product&s=confirm_order&showadder=1');"> +使用新地址</a>
            <{*---------如果地址不存在--------*}>
            <{if empty($listadder)}>
                <input type="hidden" name="adder"   value="" />
            <{/if}>
        <{else}>
          
            <{foreach item=list key=num from=$listadder}>
             <span id="ar_show_<{$list.id}>">
             <input type="radio" name="adder"   onclick="showadder();"  value="<{$list.id}>" /><{$list.province}><{$list.city}><{$list.address}><a href="javascript:alertWin('修改改收货地址','添加新的收货地址',600,400,'<{$config.weburl}>/?m=product&s=confirm_order&showadder=1&adrid=<{$list.id}>');"><font color="#0000FF">修改本地址</font></a>                     <div style="display:none;" align="right" id="ar_content_<{$list.id}>"  >
                        寄送至:<{$list.province}><{$list.city}><{$list.address}><br />
                        收货人:<{$list.name}>&nbsp;&nbsp;<{if $list.mobiel}><{$list.mobiel}><{else}><{$list.tel}><{/if}>
                     </div>       
               
             </span>  
           <br />
            <{/foreach}>
            <{if $num<4}>
            <a href="javascript:alertWin('<{$lang.add_more_user}>','添加新的收货地址',600,400,'<{$config.weburl}>/?m=product&s=confirm_order&showadder=1');">+使用新地址</a>
            <{/if}>
       <{/if}>
      </td>
    </tr>
  </table>
  <br />
  <strong>确认订单信息</strong><br />
 
  <table width="100%" border="0" cellspacing="1" bgcolor="#BAD9EF" class="order_table">
    <tr>
    <td width="21%" height="1" bgcolor="#BAD9EF">店铺产品</td>
    <td width="30%" height="1" bgcolor="#BAD9EF">单价(元)</td>
    <td width="21%" height="1" bgcolor="#BAD9EF">数量</td>
    <td width="28%" height="1" bgcolor="#BAD9EF">小计</td>
    </tr>
   <{foreach item=list from=$cart}>
    <{if !empty($list.company)}>            
    <tr>
      <td colspan="4" bgcolor="#FFFFFF" style="font-weight:bold;" scope="col">卖家：<a href="<{$config.weburl}>/shop.php?uid=<{$list.company.sell_userid}>"><{$list.company.company}></a>公司，电话：<{$list.company.tel}></td>
    </tr>
    <{/if}>
     <{foreach item=pro  from=$list.prolist}>
    <tr>
      <td bgcolor="#FFFFFF" scope="col"> <a href="<{$config.weburl}>/?m=product&s=product_detail&id=<{$pro.pid}>">
              <{assign var="img" value=$pro.pic.0}>
			  <{html_image file=uploadfile/product/$img width=80 height=80}>
              </a>
              <br /><{$pro.pname}>
       </td>
       
      <td bgcolor="#FFFFFF"><{$config.money}><{$pro.price|number_format:2}>元</td>
      <td bgcolor="#FFFFFF"><{$pro.num}></td>
      <td align="right" bgcolor="#FFFFFF"><{$config.money}><{$pro.sumprice|number_format:2}>元</td>
    </tr>    
    <tr>
    <{/foreach}>
     <{if !empty($list.company)}>        
      <td height="43" colspan="3" bgcolor="#F2F7FF" scope="col">
          给卖家留言(不能超过100个字符)：<textarea  class="textarea"   onblur="ftextarea('msg_<{$list.company.sell_userid}>','textarea');"  onmousedown="javascript:ftextarea('msg_<{$list.company.sell_userid}>','textarea1');"    id="msg_<{$list.company.sell_userid}>" name="msg_<{$list.company.sell_userid}>"></textarea></td>
      <td height="43" align="right" bgcolor="#F2F7FF" scope="col">运费方式：
           
          <{if $list.company.pu>0 or $list.company.kd>0 or $list.company.ems>0}>
              买家承担<br />
            <input name="csumprice_<{$list.company.sell_userid}>"  id="h_csumprice_<{$list.company.sell_userid}>" type="hidden" value="<{$list.company.sumprice}>"/>
           <select name="cem_<{$list.company.sell_userid}>"  id='cem_<{$list.company.sell_userid}>' onchange="select_em('<{$list.company.sell_userid}>');">
                <option value="">请选择运送方式</option>
                 <{if $list.company.pu>0}>
                <option value="pu,<{$list.company.pu}>">平邮,<{$config.money}><{$list.company.pu|number_format:2}>元</option>
                 <{/if}>
                 <{if $list.company.kd>0}>
                <option value="kd,<{$list.company.kd}>">快递,<{$config.money}><{$list.company.kd|number_format:2}>元</option>
                 <{/if}>
                 <{if $list.company.ems>0}>
                <option value="ems,<{$list.company.ems}>">EMS,<{$config.money}><{$list.company.ems|number_format:2}>元</option>
                 <{/if}>
           </select><span id="show_cem_<{$list.company.sell_userid}>">0</span><{$config.money}>
            <br />
           <{else}>
             卖家承担<br />
           <{/if}>
        
      店铺合计(含运费)：<{$config.money}><span id="s_csumprice_<{$list.company.sell_userid}>"><{$list.company.sumprice|number_format:2}>元</span></td>
    </tr> 
         <{/if}>
     <{/foreach}>  
     
</table>

  

<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td align="right">实付款：<{$config.money}><span id="s_sumprice"><{$cart.sumprice|number_format:2}></span>元
      <!--总价格-->
     <input type="hidden" name="h_sumprice" id="h_sumprice"  value="<{$cart.sumprice}>"/>
     <!--总运费-->
     <input type="hidden" name="h_emsumprice" id="h_emsumprice"  value=""/>
     <input type="hidden" name="act" value="order" />
     <input name="submit" type="submit" value="结算" />
      <br />
       <div id="show_adder_c">
       
       </div>
     
     </td>
  </tr>
</table>
</form>


</div>
<{include file="shop_footer.htm"}>